/**
 * 
 */
package langnstats.project.languagemodel.srilm;

import java.io.Serializable;

/**
 * @author qing
 *
 */
public class SriLMParameters implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 497429517274890579L;
	// Discounting Method
	public enum DiscountingMethod implements Serializable{
		Good_Turing,
		Absolute,
		Witten_Bell,
		Keyser_Ney
	}
	
	
	//private static String executable = "/afs/cs/user/qing/srilm/bin/i686-gcc4/ngram-count";
	private static String executable = System.getProperty("ngramexec", "/afs/cs/user/qing/srilm/bin/i686-gcc4/ngram-count");
	private DiscountingMethod discountingMethod = DiscountingMethod.Good_Turing;
	private int order = 3;
	private String vocab = "";
	private String train = "";
	private String lm = "";
	
	private int cutoff[];
	private int maxdisc[];
	
	public int[] getCutoff() {
		return cutoff;
	}
	public void setCutoff(int[] cutoff) {
		this.cutoff = cutoff;
	}
	public int[] getMaxdisc() {
		return maxdisc;
	}
	public void setMaxdisc(int[] maxdisc) {
		this.maxdisc = maxdisc;
	}
	public DiscountingMethod getDiscountingMethod() {
		return discountingMethod;
	}
	public void setDiscountingMethod(DiscountingMethod discountingMethod) {
		this.discountingMethod = discountingMethod;
	}
	public int getOrder() {
		return order;
	}
	public void setOrder(int order) {
		this.order = order;
	}
	public String getVocab() {
		return vocab;
	}
	public void setVocab(String vocab) {
		this.vocab = vocab;
	}
	public String getTrain() {
		return train;
	}
	public void setTrain(String train) {
		this.train = train;
	}
	public SriLMParameters(DiscountingMethod discountingMethod, int order,
			String lm, String train, int[] cutoff, int[] maxdisc) {
		super();
		this.discountingMethod = discountingMethod;
		this.order = order;
		this.lm = lm;
		this.train = train;
		this.cutoff = cutoff;
		this.maxdisc = maxdisc;
	}
	public static String getExecutable() {
		return executable;
	}
	public static void setExecutable(String executable) {
		SriLMParameters.executable = executable;
	}
	
	public String toString(){
		StringBuffer cml = new StringBuffer();
		cml.append(executable);
		cml.append(" -text ");
		cml.append(this.train);
		cml.append(" -order ");
		cml.append(order);
		cml.append(" -write - | ");
		cml.append(executable);
		cml.append(" -read - -order ");
		cml.append(order);
		cml.append(" -lm ");
		cml.append(lm);
		cml.append(" -gt1max 0 ");
		for(int i=1 ;i < order; i++){
			cml.append(" -gt" +(i+1)+"min ");
			cml.append(cutoff[i]);
			cml.append(" -gt" +(i+1)+"max ");
			cml.append(maxdisc[i]);
			if(discountingMethod.equals(DiscountingMethod.Absolute)){
				cml.append(" -cdiscount" + (i+1)+ " 0.5 ");
			}else if(discountingMethod.equals(DiscountingMethod.Witten_Bell)){
				cml.append(" -wbdiscount" + (i+1) + " ");
			}else if(discountingMethod.equals(DiscountingMethod.Keyser_Ney)){
				cml.append(" -kndiscount" + (i+1) + " ");
			}
		}
		return cml.toString();
		
	}
	public String getLm() {
		return lm;
	}
	public void setLm(String lm) {
		this.lm = lm;
	}
	
	
}
